/*
 * @Author: szx
 * @Date: 2022-07-20 14:03:48
 * @LastEditTime: 2022-07-20 14:16:49
 * @Description:
 * @FilePath: \leetcode\700-799\735\735.js
 */
/**
 * @param {number[]} asteroids
 * @return {number[]}
 */
var asteroidCollision = function (asteroids) {
    const res = [];
    for (let aster of asteroids) {
        let right = true;
        while (res.length && res[res.length - 1] > 0 && aster < 0) {
            const a = res[res.length - 1];
            if (a <= -aster) res.pop();
            if (a >= -aster) right = false;
        }
        if (right) res.push(aster);
    }
    return res;
};
